thresh=3.5, edge=2, guard=[1,1,1]
snr_hi=3.5, snr_lo=2, edgech=4, minbeam=2, nguard=[1,1], min_thresh_ch=2
thresh=3.5, edge=2, smopar=[14.,0.], guard=[2,2,2]
snr_hi=3.5, snr_lo=2, edgech=4, fwhm=14, minbeam=2, nguard=[2,2], min_thresh_ch=2
from edge_pydb import EdgeTable
from matplotlib import pyplot as plt
import numpy as np
import os
import datetime
from astropy.io import fits
from matplotlib.backends.backend_pdf import PdfPages
from astropy.wcs import WCS
import warnings
warnings.filterwarnings("ignore")
pdfout=False
def implots(gallist=None, line='co', imdir='.', imtype='smo7_dil.mask',
lbl='edge', xrange=60., nx=7, ny=5, cmap='CMRmap_r', pdfout=False,
ctr_tab=None, errtype=None, errmax=20):
pages = int(np.ceil(float(len(gallist)) / (nx*ny)))
if pdfout:
pp = PdfPages(lbl + '.' + imtype + '.pdf')
for num in range(0,pages):
aa = nx*ny*num
bb = nx*ny+aa
galpage = gallist[aa:bb]
fig = plt.figure(figsize=(20,14))
for i, galname in enumerate(galpage):
infile = imdir+'/'+galname+'.'+line+'.'+imtype+'.fits.gz'
if os.path.exists(infile):
tempim = np.squeeze(fits.getdata(infile))
if tempim.ndim == 3:
tempim = np.nansum(tempim, axis=0)
temphd = fits.getheader(infile)
xctr = temphd['CRPIX1']
yctr = temphd['CRPIX2']
if ctr_tab is not None:
w = WCS(temphd)
ractr = ctr_tab.loc[galname]['ledaRA']
dcctr = ctr_tab.loc[galname]['ledaDE']
listofzeros = [0] * temphd['NAXIS']
coords = w.wcs_pix2world([listofzeros], 0)
coords[0][0] = ractr
coords[0][1] = dcctr
ctrpx = w.wcs_world2pix(coords, 0)
xctr = round(ctrpx[0][0])
yctr = round(ctrpx[0][1])
if errtype is not None:
errfile = imdir+'/'+galname+'.'+line+'.'+errtype+'.fits.gz'
errim = np.squeeze(fits.getdata(errfile))
tempim[errim > errmax] = np.nan
else:
nomrange = max(xrange,60.)
tempim = np.zeros((int(2*nomrange+1),int(2*nomrange+1)))
temphd = None
xctr = nomrange
yctr = nomrange
ax = plt.subplot(ny,nx,i+1)
xran = [xctr-xrange, xctr+xrange]
yran = [yctr-xrange, yctr+xrange]
ax.set_xlim(xran)
ax.set_ylim(yran)
if imtype.split('.')[1] == 'mask':
ax.imshow(tempim, cmap=cmap, vmin=0, vmax=35)
elif imtype.split('.')[1] == 'mom0':
ax.imshow(tempim, cmap='CMRmap_r', norm=None)
elif imtype.split('.')[1] == 'mom1':
ax.imshow(tempim, cmap='jet', norm=None)
if temphd is not None:
plt.plot([xctr], [yctr], marker='+', lw=3, ms=14, color='blue')
ax.xaxis.set_ticks([])
ax.yaxis.set_ticks([])
plt.text(0.05,0.9,galname,ha='left',va='center',transform=ax.transAxes,
bbox=dict(facecolor='white', edgecolor='none', pad=3.0))
fig.subplots_adjust(hspace=0.05)
fig.subplots_adjust(wspace=0.05)
if pdfout:
pp.savefig(bbox_inches = 'tight', pad_inches=0.1)
plt.close()
else:
plt.show()
if pdfout:
d = pp.infodict()
d['Title'] = 'EDGE Gallery'
d['Author'] = 'Tony Wong'
d['CreationDate'] = datetime.datetime.today()
pp.close()
return
leda = EdgeTable('edge_leda.csv', cols=['Name', 'ledaRA', 'ledaDE', 'ledaPA', 'ledaIncl'])
leda['ledaRA'].convert_unit_to('deg')
leda.add_index('Name')
print(leda)
gallist=leda['Name'].tolist()
print('IDL Results')
implots(gallist, lbl='idl', imtype='smo7_dil.mask', imdir='../smo7_idlmom', ctr_tab=leda, pdfout=pdfout)
print('Python Results')
implots(gallist, lbl='py', imtype='smo7_dil.mask', imdir='../smo7_mom_vrad', ctr_tab=leda, pdfout=pdfout)
print('IDL Results')
implots(gallist, lbl='idl', imtype='smo7_dil.mom1', imdir='../smo7_idlmom', ctr_tab=leda, pdfout=pdfout)
print('Python Results')
implots(gallist, lbl='py', imtype='smo7_dil.mom1', imdir='../smo7_mom_vrad', ctr_tab=leda, pdfout=pdfout)
print('Python Results with error masking')
implots(gallist, lbl='py', imtype='smo7_dil.mom1', imdir='../smo7_mom_vrad', ctr_tab=leda,
errtype='smo7_dil.emom1', pdfout=pdfout)
print('IDL Results')
implots(gallist, lbl='idl', imtype='smo7_smo.mask', imdir='../smo7_idlmom', ctr_tab=leda, pdfout=pdfout)
print('Python Results')
implots(gallist, lbl='py', imtype='smo7_smo.mask', imdir='../smo7_mom_vrad', ctr_tab=leda, pdfout=pdfout)
print('IDL Results')
implots(gallist, lbl='idl', imtype='smo7_smo.mom0', imdir='../smo7_idlmom', ctr_tab=leda, pdfout=pdfout)
print('Python Results')
implots(gallist, lbl='py', imtype='smo7_smo.mom0', imdir='../smo7_mom_vrad', ctr_tab=leda, pdfout=pdfout)
print('IDL Results')
implots(gallist, lbl='idl', imtype='smo7_smo.mom1', imdir='../smo7_idlmom', ctr_tab=leda, pdfout=pdfout)
print('Python Results')
implots(gallist, lbl='py', imtype='smo7_smo.mom1', imdir='../smo7_mom_vrad', ctr_tab=leda, pdfout=pdfout)
print('Python Results with error masking')
implots(gallist, lbl='py', imtype='smo7_smo.mom1', imdir='../smo7_mom_vrad', ctr_tab=leda,
errtype='smo7_smo.emom1', errmax=40, pdfout=pdfout)